/**
 * 医疗资源-概况
 */
new IdealImageSlider.Slider('#slider_survery');
orange.dataSurvey = {
	init: function() {
		$.post('org/getOrgJsonById', {orgId: orange.getOrganizationData().id}, function(data) {
			//alert(data.orgName);
			$('#org_dataSurveyForm').form('load', data);
			$('#add_dataSuvRightGrid').datagrid({
				url:'diseaseType/getDisNamesByDisIds',
				queryParams:{disIds:data.clinicSpeciality},
				onLoadSuccess:function(){
					loadSurveySpeciality();
				}
			});
		});
	},
	submit: function() {
		var guid = $('#guid').val();
		if(guid==null) {
			this.saveSurvey('org/add');
		} else {
			this.saveSurvey('org/edit');
		}
	},
	saveSurvey: function(url) {
		$.ajax({
			url:url,
			type:'post',
			data:orange.systemPage.getFormData('org_dataSurveyForm'),
			success:function(data){
				if(data && data.success ==true){
					$.messager.show({
	        			title:'提示',
	        			msg:'保存成功！'
	        		});
				}else{
					$.messager.alert('提示',data.errorMsg);
				}
			}
		});
	},
	//添加图片上传的选择操作
	addImageFileUpload: function() {
		$.ajaxFileUpload({  
	        url:'image/orgImageUpload',  
	        secureuri:false,  
	        fileElementId:'surveyImageFile',  
	        dataType: 'json',  
	        data:{
	        	orgId:orange.getOrganizationData().id,
	        	guid:orange.getOrganizationData().id,
	        	staffType:''
	        },  
	        success: function (data, status)  
	        {  
	        	debugger;
	        	$('#addSuv_loading').attr('src',data.data);
	            
	        },  
	        error: function (data, status, e)  
	        {  
	            //这里处理的是网络异常，返回参数解析异常，DOM操作异常  
	            alert("上传发生异常");  
	        }  
	    });
	}
	
};

orange.dataSurvey.init();	//	初始化医疗资源-概况信息

/**
 * --医疗专长的下拉框
 */
$('#addSurvey_dataSpeciality').combobox({
	width: 262,
	editable: false,
	panelWidth: 485,
	panelHeight:285,
	onHidePanel: function() {
		loadSurveySpeciality();
	}
});
$('#add_surveySP').appendTo($('#addSurvey_dataSpeciality').combo('panel'));

function loadSurveySpeciality(){
	 var data = $('#add_dataSuvRightGrid').datagrid('getData').rows;
     var value = [];
     var text = '';
     if(data.length!==0) {
         for (var i = 0; i < data.length; i++) {
             value.push(data[i].guid);
             text += data[i].typeName;
             if (i!==data.length-1) {
                 text += ',';
             }
         };
     }
     $("#addSurvey_dataSpeciality").combo('setValue',value.join(","));
     $("#addSurvey_dataSpeciality").textbox('setText',text);
}
/**
 * 医疗专长搜索框定义
 */
$('#add_dataSuvSearch').searchbox({ 
	prompt:'描述搜索',
	width:172,
	searcher:function(value,name){ 
		$('#add_dataSuvLeftGrid').datagrid('load',{
			searchstr : value,
		});
	}
}); 

/*
 * 医疗专长左边的数据表格配置
 */
$('#add_dataSuvLeftGrid').datagrid({
	url:'diseaseType/findDiseaseTypebyPage',
	singleSelect: true,
	width:275,
	height:250,
	pagination: true, //是否分页
	pageSize: 6, //每页显示的记录条数，默认为10 
	pageList:[6],
	columns: [[
        {field: 'guid',title: '编码',hidden:true},
		{field: 'typeParent',title: '标准',width: 60},
		{field: 'typeName',title: '名称',width: 100},
		{field: 'typeDescribe',title: '描述',width: 100}
	]],
	onSelect: function(rowIndex, rowData) {
		var data = $('#add_dataSuvRightGrid').datagrid('getData').rows;
		var flag = true;
		if(data.length!==0) {
			for (var i = 0; i < data.length; i++) {
				if(data[i].guid==rowData.guid) {
					flag = false;
				}
			};
		}
		if (flag && data.length<5) {
			$('#add_dataSuvRightGrid').datagrid('insertRow',{
				index:0,
				row:rowData
			});
		}
	}
});

/**
 * 医疗专长已选择的数据表格配置
 */
$('#add_dataSuvRightGrid').datagrid({
	singleSelect: true,
	width:185,
	height:250,
    columns: [[
        {field: 'guid',title: '编码',hidden:true},
		{field: 'typeParent',title: '标准',width: 60},
		{field: 'typeName',title: '名称',width: 100},
	]],
	onSelect: function(rowIndex, rowData) {
		$('#add_dataSuvRightGrid').datagrid('deleteRow',rowIndex);
	}
});
